class Solution7 {
    public int maxProfit(int[] prices) {
         int len = prices.length ;
          int[] f = new int[len] ;
          int[] g = new int[len]; 
           f[0] = -prices[0] ;
           for(int i=1 ; i< len ; i ++){
              f[i] = Math.max(f[i-1] , g[i-1]-prices[i]);
              g[i] = Math.max(g[i-1] , f[i-1]+prices[i]);
           }
          return Math.max(f[len-1] , g[len-1]);
    }
}